﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Objects;
using System.Data.Objects.DataClasses;
using System.Linq.Expressions;

namespace IRC.IRepairClouds.DataLayer
{
    internal static class EntityGetter
    {
        internal static TEntity Get<TEntity>(this ObjectQuery<TEntity> entities, bool throwIfNotExists, DbInclude<TEntity> include, Expression<Func<TEntity, bool>> condition) where TEntity : EntityObject
        {
            entities.ThrowIfNull("entities");
            condition.ThrowIfNull("condition");

            if (include != null)
                entities = include(entities);

            return entities.Where(condition).GetSingle();
        }
    }
}
